package cn.tedu.csmall.product.controller;

import cn.tedu.csmall.product.pojo.dto.AlbumAddNewDTO;
import cn.tedu.csmall.product.pojo.dto.AlbumUpdateDTO;
import cn.tedu.csmall.product.pojo.vo.AlbumListItemVO;
import cn.tedu.csmall.product.pojo.vo.AlbumStandardVO;
import cn.tedu.csmall.product.service.IAlbumService;
import cn.tedu.csmall.product.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@Api(tags = "03.相册管理模块")
@RestController
@RequestMapping("/albums")
public class AlbumController {

    @Autowired
    private IAlbumService IAlbumService;

    public AlbumController() {
        log.debug("创建控制器对象：AlbumController");
    }

    @ApiOperation("添加相册")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult addNew(@Valid AlbumAddNewDTO albumAddNewDTO) {
        log.debug("开始处理【添加相册】的请求，请求参数：{}",albumAddNewDTO);
        IAlbumService.addNew(albumAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除相册")
    @ApiOperationSupport(order = 200)
    @ApiImplicitParam(name = "id", value = "相册id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/deleteById")
    public JsonResult deleteById(@PathVariable("id") Long id){
        log.debug("开始处理【根据id删除相册】的请求，参数：{}",id);
        IAlbumService.deleteById(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改相册基本信息")
    @ApiOperationSupport(order = 300)
    @ApiImplicitParam(name = "id", value = "相册id", required = true, dataType = "long")
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult update(@PathVariable Long id, AlbumUpdateDTO albumUpdateDTO){
        log.debug("开始处理【修改相册基本信息】的请求，参数id: {}，新数据：{}",id ,albumUpdateDTO);
        IAlbumService.updateInfoById(id,albumUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("查询相册详情")
    @ApiOperationSupport(order = 410)
    @ApiImplicitParam(name = "id", value = "相册id", required = true, dataType = "long")
    @GetMapping ("/{id:[0-9]+}")
    public JsonResult getStandardById(@PathVariable Long id){
        log.debug("开始处理【根据id查询相册详情】的请求，参数：{}",id);
        AlbumStandardVO album = IAlbumService.getStandardById(id);
        return JsonResult.ok(album);
    }


    @ApiOperation("查询相册列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult list(){
        log.debug("开始处理【查询相册列表】请求，参数：“无");
        List<AlbumListItemVO> list = IAlbumService.list();
        return JsonResult.ok(list);
    }

}
